<template>
	<!-- 20230201 -->
	<view class="mall-my-refund-btn-cn">
		<!-- 组件内容 -->
		<view class="cn-content">
			<view class="flex align-center justify-end">
				<!-- 待审核 -->
				<block v-if="status == 1">
					<view class="btn-60-main" @click="cancel()">撤销申请</view>
				</block>

				<!-- 已退款 -->
				<block v-if="status == 2">
					<view class="btn-60-cc" @click="del()">删除记录</view>
				</block>

				<!-- 已拒绝 -->
				<block v-if="status == 3">
					<view class="btn-60-cc" @click="del()">删除记录</view>
				</block>

				<!-- 已撤销 -->
				<block v-if="status == 4">
					<view class="btn-60-cc" @click="del()">删除记录</view>
				</block>
			</view>
		</view>

		<!-- 组件浮层 -->
		<view class="cn-layer">

		</view>
	</view>
</template>

<script>
	import mall from "../api/mall.js"
	export default {
		props: {
			// 退款ID
			refundId: {
				type: [Number, String],
				default: ''
			},
			// 当前index
			index: {
				type: [Number, String],
				default: ''
			},
			// 状态 1--待审核  2--已退款 3--已拒绝 4-已撤销
			status: {
				type: [Number, String],
				default: ''
			},
			// 打开类型 1--列表页 2--详情页
			openType: {
				type: [Number, String],
				default: 1
			},
		},

		data() {
			return {

			}
		},


		methods: {

			/**
			 * 撤销申请
			 * @date 2023-02-24
			 */
			cancel() {
				this.cn.confirm('确认撤销退款吗').then(res => {
					if (res.confirm) {
						mall.refund.cancelRefundOrder(this.refundId).then(res => {
							if (res.code == 0) {
								if (this.openType == 1) {
									uni.redirectTo({
										url: '/pages/mall/my/refundList'
									})
								} else {
									uni.redirectTo({
										url: '/pages/mall/my/refundDetail?id=' + this.refundId
									})
								}
							}
						})
					}
				})
			},

			/**
			 * 退款删除
			 * @date 2023-02-24
			 */
			del() {
				this.cn.confirm('确认删除记录').then(res => {
					if (res.confirm) {
						mall.refund.deleteRefundOrder(this.refundId).then(res => {
							if (res.code == 0) {
								this.cn.toast(res.msg)
								if (this.openType == 1) {
									uni.redirectTo({
										url: '/pages/mall/my/refundList'
									})
								} else {
									uni.navigateBack()
								}
							}
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
</style>
